/*日期插件的指令*/
var datatime=angular.module('datatime',[]);
datatime.directive('ngTime',function(){
    return{
        restrict : 'A',
        link:function($scope, $element, $attrs){
            /*$.datetimepicker.setLocale('ch');//设置中文
            $element.datetimepicker({
                lang:'ch',
                format:'Y-m-d H:i:s',
                formatTime:'H:i',
                formatDate:'Y-m-d'
               // endMins:'59'
            });*/
            var date;
            var startDate;
            var endDate;
            var startView=2;
            if($attrs.maxDate=="today"){
                date=new Date();
                var todayPre= new Date(date.getTime()- 2*24*60*60*1000);
                startDate=new Date(todayPre.getFullYear(),todayPre.getMonth(),todayPre.getDate(),"00","00","00");
                endDate=new Date(date.getFullYear(),date.getMonth(),date.getDate(),"23","59","59");
                startView=1;
            }else if($attrs.maxDate=="yesterday"){
                date=new Date();
                startDate="";
                //
                var preDate=new Date(date.getTime()- 1*24*60*60*1000)
                endDate=new Date(preDate.getFullYear(),preDate.getMonth(),preDate.getDate(),"23","59","59");
            }else if($attrs.minDate=="threemonth"){
                date=new Date();
                var todayPre= new Date(date.getTime()- 92*24*60*60*1000);
                startDate=new Date(todayPre.getFullYear(),todayPre.getMonth(),todayPre.getDate(),"00","00","00");
                endDate=new Date(date.getFullYear(),date.getMonth(),date.getDate(),"23","59","59");
            }
            $element.datetimepicker({
                format: 'yyyy-mm-dd hh:ii:ss',
                language: 'zh-CN',/*加载日历语言包，可自定义*/
                startDate:startDate,
                endDate:endDate,
                weekStart: 1,/*,一周从哪天开始*/
                todayBtn: 1,/*今天的按钮是否显示*/
                todayHighlight: 1,/*高亮当前日期*/
                startView: startView,/*日期时间选择器打开之后首先显示的视图。*/
                autoclose:1,/*当选择一个日期之后是否立即关闭此日期时间选择器。*/
                minView: 1/*日期时间选择器所能够提供的最精确的时间选择视图。*/
            });
        }
    }
})
/*datatime.directive('ngTimeEnd',function(){
    return{
        restrict : 'A',
        link:function($scope, $element, $attrs){
            $.datetimepicker.setLocale('ch');//设置中文
            $element.datetimepicker({
                lang:'ch',
                format:'Y-m-d H:i:s',
                formatTime:'H:i',
                formatDate:'Y-m-d',
                 endMins:'59'
            });
        }
    }
})*/
datatime.directive('ngDay',function(){
    return{
        restrict : 'A',
        link:function($scope, $element, $attrs){
          /*  $.datetimepicker.setLocale('ch');//设置中文
            $element.datetimepicker({
                lang:'ch',
                format:'Y-m-d',
                formatDate:'Y-m-d',
                timepicker:false

            });*/
            $element.datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',/*加载日历语言包，可自定义*/
                weekStart: 1,/*,一周从哪天开始*/
                todayBtn: 1,/*今天的按钮是否显示*/
                todayHighlight: 1,/*高亮当前日期*/
                startView: 2,/*日期时间选择器打开之后首先显示的视图。*/
                autoclose:1,/*当选择一个日期之后是否立即关闭此日期时间选择器。*/
                minView: 2/*日期时间选择器所能够提供的最精确的时间选择视图。*/
            });
        }
    }
})

datatime.directive('ngMonth',function(){
    return{
        restrict : 'A',
        link:function($scope, $element, $attrs){
           /* $.datetimepicker.setLocale('ch');//设置中文
            $element.datetimepicker({
                lang:'ch',
                format:'Y-m',
                formatDate:'Y-m',
                timepicker:false

            });*/
            $element.datetimepicker({
                format: 'yyyy-mm',
                language: 'zh-CN',/*加载日历语言包，可自定义*/
               // weekStart: 1,一周从哪天开始
                //todayBtn: 1,今天的按钮是否显示
                //todayHighlight: 1,高亮当前日期
                startView: 3,/*日期时间选择器打开之后首先显示的视图。 */
                autoclose:1,/*当选择一个日期之后是否立即关闭此日期时间选择器。*/
                minView: 3/*日期时间选择器所能够提供的最精确的时间选择视图。*/
            });
        }
    }
})